var Net = require('net');
var Co = require('constant');
var SingleEventTarget = require('SingleEventTarget');
cc.Class({
    extends: cc.Component,

    properties: {
        label: {
            default: null,
            type: cc.Label
        },
        // defaults, set visually when attaching this script to the Canvas
        text: 'Hello, World!'
    },

    // use this for initialization
    onLoad: function () {
        this.label.string = this.text;   
        
        Net.init();
    },
    onEnable:function(){
        SingleEventTarget.on(Co.MSG_SOCKET_ONOPEN,this.socketOpen,this);
    },
    onDisable:function(){
        SingleEventTarget.off(Co.MSG_SOCKET_ONOPEN,this.socketOpen,this);
    },
    socketOpen:function(customEvent){
        cc.log("HelloWorld","socketOpen data = "+customEvent.detail);
        var userData = {};//设备登录信息
        userData.deviceId = Date.parse(new Date())/1000+"_"+Math.random().toString(36).substr(2);
        Net.login(userData);
    },
    // called every frame
    update: function (dt) {

    },
});
